{% extends 'admin/base.html' %}

{%load comm_extras %}

{% block head_soruce %}
<script type="text/javascript">
	var urlDelete = '{%url admin-category-delete-json 88888888 %}';

	function delCategory(id){
		if(!confirm('你确定要删除吗？')){return;}
		var url = urlDelete.replace('88888888', id);
		$.ajax({
			url: url,
			type: 'get',
			dataType: 'json',
			success: function(result, textStatus){
				if(result){
					if(result.success){
						window.location.reload();
					}else{
						alert(result.err_msg);
					}
				}else{
					alert('删除失败');
				}
			},
			error: function(xhr, textStatus, errorThrown){
			}
		});
	}

</script>
{% endblock %}

{% block main_content %}
	<h1>分类管理</h1>
	{%if categorys%}
		<ul id="movie-form" class="form">
		{%for category in categorys %}
			<li>
				ID：{{category.id}}&nbsp;&nbsp;&nbsp;&nbsp;Index：{{category.index}}&nbsp;&nbsp;&nbsp;&nbsp;{{category.title}}
				<a href="{%url admin-category-edit-view category.id%}">编辑</a>
				<a href="javascript:void(0)" onclick="delCategory({{category.id}});">删除</a>
			</li>
			{%for child in category.subItems %}
				<li>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID：{{child.id}}&nbsp;&nbsp;&nbsp;&nbsp;Index：{{child.index}}&nbsp;&nbsp;&nbsp;&nbsp;{{child.title}}
					<a href="{%url admin-category-edit-view child.id%}">编辑</a>
					<a href="javascript:void(0)" onclick="delCategory({{child.id}});">删除</a>
				</li>
			{%endfor%}
		{%endfor%}
		</ul>
	{%else%}
		<div>还没添加分类</div>
	{%endif%}


{% endblock %}
